# -*- coding: utf-8 -*-
import telnetlib
import logging
import requests


class IpCommon(object):

	def __init__(self):
		pass

	@staticmethod
	def ip_is_usable(ip, port):
		try:
			telnetlib.Telnet(ip, port=int(port), timeout=100)
		except Exception as e:
			logging.info("ip_is_usable_Exception:%s" % e)
			return False
		else:
			return True
	# # ByRequests测试IP是否有效
	# def ip_is_usable_by_requests(proxy_ip)
	# 	try:
	# 		requests.get('http://www.baidu.com/', proxies={"http":+proxy_ip})
	# 	except:
	# 		return False
	# 	else:
	# 		return True